import {connect} from 'react-redux';
import {View} from '@tarojs/components';
import {AtIcon, AtButton} from 'taro-ui';
import Taro from "@tarojs/taro";
import './index.less'
import moment from "moment/moment";

function fleetCard(i, index, dispatch) {
  const {
    operationType = '',
    fleetName = '',
    cashBalance : balance = '56.56',
  } = i;
  return (
    <View className='cardWrap' key={index}>
      {/*<View className='cardTitle'>*/}
      {/*    {i?.fleetName}*/}
      {/*</View>*/}
      <View className='textLine'>
        <View>
          <AtIcon prefixClass='icon' value='chedui' size={36} color='#048fff' />
        </View>
        <View>
          <View className='type'>车队名称: <span className='spanView' style={{color: '#ff9000', display: 'inline-block'}}>{fleetName}</span></View>
          <View className='type'>账户余额: <span className='spanView' style={{color: '#1a9d34', display: 'inline-block'}}>¥{(balance / 100).toFixed(2)}</span></View>
        </View>
        <View>
          <View
              className='money'
              onClick={() => {
                dispatch({
                  type: 'wallet/setState',
                  payload: {
                    currentFleetAccount: {
                      ...i
                    }
                  }
                })
                Taro.navigateTo({url: `/moduleA/pages/order/fleetOrder?fleetAccountId=${i.fleetId}&fleetName=${i.fleetName}`})
              }}
          >
            车队流水<AtIcon value='chevron-right' size='18' />
          </View>
          <View
              className='car'
              onClick={() => {
                dispatch({
                  type: 'wallet/setState',
                  payload: {
                    currentFleetAccount: {
                      ...i
                    }
                  }
                })
                Taro.navigateTo({url: `/moduleB/pages/fleetCars/index?fleetAccountId=${i.fleetId}&fleetName=${i.fleetName}`})
              }}
          >
            车队车辆<AtIcon value='chevron-right' size='18' />
          </View>
        </View>
      </View>
    </View>
  )
}
function TeamAccount(props) {
  const { fleetList = [], dispatch} = props;
  return (
    <View>
      <View className='rechargeWrap'>
        {fleetList.map((i, index) => fleetCard(i, index, dispatch))}
      </View>
    </View>
  )
}

function mapStateToProps({wallet = {}}) {
  return {
    ...wallet
  }
}

export default connect(mapStateToProps)(TeamAccount)
